package world.snowcrystal.nova.controller;


import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import world.snowcrystal.nova.common.BaseResponse;
import world.snowcrystal.nova.common.ErrorCode;
import world.snowcrystal.nova.common.ResultUtils;
import world.snowcrystal.nova.exception.ThrowUtils;
import world.snowcrystal.nova.mapper.UserAnswerStatisticMapper;
import world.snowcrystal.nova.statistic.AppAnswerCount;
import world.snowcrystal.nova.statistic.ResultAnswerCount;

import java.util.List;

@RestController
@RequestMapping("/statistic/")
@RequiredArgsConstructor
public class StatisticController {

    private final UserAnswerStatisticMapper userAnswerStatisticMapper;




    @GetMapping("/answer-count")
    public BaseResponse<List<AppAnswerCount>> getAnswerCount() {
        return ResultUtils.success(userAnswerStatisticMapper.getTop10AppAnswerCount());
    }
    @GetMapping("/answer-result-distribution/{appId}")
    public BaseResponse<List<ResultAnswerCount>> getAnswerResultDistribution(@PathVariable Long appId) {
        ThrowUtils.throwIf(appId == null || appId <=0 , ErrorCode.PARAMS_ERROR);
        return ResultUtils.success(userAnswerStatisticMapper.getResultAnswerCountByAppId(appId));
    }



}
